#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,xbmcplugin,xbmcgui

import urllib,urllib2,re

import xbmc, imp
path=xbmc.translatePath('Q:\\plugins\\hoster\\oracle\\oracle1.py')
oracle1=imp.load_source("oracle1", "oracle1.py", open(path,'r'))

debug=1
dstr=""

#this should become the libary for handling folders and interface
def get_verion():
	#or look at the filename
	return 1

	
	
"""	
def get_links_by_get_link(array):
	links=[]
	for method,args,item in array:
		links.append((method,method(in args)))
	return links
"""	
	
	
	
def MIRROR_LIST(array):
	for method,args,item in array:
		#item: image,title,filename,hoster
		i=0
		argstr=""
		for arg in args:
			argstr=argstr+"args["+str(i)+"],"
			i=i+1
		execstr="result=oracle1."+method+"("+argstr[:-1]+")"
		
		if debug > 0: print dstr+"*oracle*interface1*MIRROR_LIST* execstr: "+ execstr
		exec execstr
		if debug > 0: print dstr+"*oracle*interface1*MIRROR_LIST* result: "+ str(result)
		for status,link,image,title,filename,captcha,hoster in result:
			addDir(str(item[1])+"*"+str(item[2])+"*"+str(hoster), str(link) , 4, str(item[0]))

def LINK_LIST():
	print "nope"
def CAPTCHA_LIST():
	print "nope"
def ACTION_LIST(url):
	if debug > 0: print dstr+"*oracle*interface*ACTION_LIST('"+str(url)+"')"
	addLink("play video", str(url), "")
	print "nope"
#view
#download
#download & view
#remove from history
#[delete download]
#settings

def DOWNLOAD_LIST():
	print "nope"

def HISTORY_LIST():
	print "nope"

def SETTINGS():
	print "nope"

		

def addLink(name,url,iconimage):
		ok=True
		liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
		liz.setInfo( type="Video", infoLabels={ "Title": name } )
		ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
		return ok


def addDir(name,url,mode,iconimage):
		u=xbmc.translatePath('plugin://hoster/oracle/')+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
		ok=True
		liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
		liz.setInfo( type="Video", infoLabels={ "Title": name} )
		ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
		return ok
		

	
